<template>
  <div class="home-overview">
    <!-- 用户信息 -->
    <div class="user-meta">
      <div class="avatar">
        <img v-if="member.sex" :src="member.sex === '男' ? manImage : womanImage" />
      </div>
      <h4>{{ member.name }}</h4>
    </div>
    <div class="item">
      <a href="javascript:;">
        <span class="iconfont icon-hy"></span>
        <p>会员中心</p>
      </a>
      <a href="javascript:;">
        <span class="iconfont icon-aq"></span>
        <p>安全设置</p>
      </a>
      <a href="javascript:;">
        <span class="iconfont icon-dw" @click="openDialog()"></span>
        <p>地址管理</p>
      </a>
    </div>
  </div>
  <div class="user-info-container">
    <div class="user-info-panel">
      <div class="header">
        <h4>用户信息</h4>
      </div>
      <div class="total">
        <dl>
          <dt>账号：</dt>
          <dd>{{ member.account }}</dd>
        </dl>
        <dl>
          <dt>性别：</dt>
          <dd>{{ member.sex }}</dd>
        </dl>
        <dl>
          <dt>手机号：</dt>
          <dd>{{ member.phone }}</dd>
        </dl>
        <dl>
          <dt>余额：</dt>
          <dd>¥{{ member.balance }}</dd>
        </dl>
      </div>
    </div>
  </div>

  <AddressDialog ref="addressDialog"/>

</template>

<script setup>
import { getMemberAPI } from "@/apis/user";
import { onMounted, ref } from "vue";
import manImage from '@/assets/images/man-default.png';
import womanImage from '@/assets/images/woman-default.png';
import AddressDialog from "@/components/Address/AddressDialog.vue";

const member = ref({});
const addressDialog = ref(null);

const getMember = async () => {
  const res = await getMemberAPI();
  member.value = res.data;
};
const openDialog = () => {
  addressDialog.value.open();
};

onMounted(() => getMember());
</script>

<style scoped lang="scss">
.home-overview {
  height: 132px;
  background: url(@/assets/images/center-bg.png) no-repeat center / cover;
  display: flex;

  .user-meta {
    flex: 1;
    display: flex;
    align-items: center;

    .avatar {
      width: 85px;
      height: 85px;
      border-radius: 50%;
      overflow: hidden;
      margin-left: 60px;

      img {
        width: 100%;
        height: 100%;
      }
    }

    h4 {
      padding-left: 26px;
      font-size: 18px;
      font-weight: normal;
      color: white;
    }
  }

  .item {
    flex: 1;
    display: flex;
    align-items: center;
    justify-content: space-around;

    &:first-child {
      border-right: 1px solid #f4f4f4;
    }

    a {
      color: white;
      font-size: 16px;
      text-align: center;

      .iconfont {
        font-size: 32px;
      }

      p {
        line-height: 32px;
      }
    }
  }
}

.user-info-container {
  margin-top: 20px;
  border-radius: 4px;
  background-color: #fff;
}

.user-info-panel {
  background-color: #fff;
  padding: 0 20px;
  margin-top: 20px;
  height: 400px;

  .header {
    height: 66px;
    border-bottom: 1px solid #f5f5f5;
    padding: 18px 0;
    display: flex;
    justify-content: space-between;
    align-items: baseline;

    h4 {
      font-size: 22px;
      font-weight: 400;
    }
  }

  .total {
    dl {
      display: flex;
      justify-content: flex-end;
      line-height: 50px;

      dt {
        i {
          display: inline-block;
          width: 2em;
        }
      }

      dd {
        width: 240px;
        text-align: right;
        padding-right: 70px;

        &.price {
          font-size: 20px;
          color: $priceColor;
        }
      }
    }
  }
}
</style>